package com.test.mooan.labama.activity_fragment_boom.process_boom;

import android.os.Bundle;
import android.widget.Button;

import com.test.mooan.labama.R;
import com.test.mooan.labama.activity_fragment_boom.base_boom.BaseInfoActivity_boom;
import com.test.mooan.labama.bean_boom.config_info_boom.UrlInfo_boom;
import com.test.mooan.labama.bean_boom.user_info_boom.ActList_boom;
import com.test.mooan.labama.dialog_boom.ln_boom.SubmitActInfoDialog_Fr_boom;
import com.test.mooan.labama.utils_boom.helper_boom.UserInfoHelper_boom;
import com.test.mooan.labama.utils_boom.http_boom.HttpManager_boom;
import com.test.mooan.labama.view_boom.module_boom.AddBkActView_Cote_boom;
import com.test.mooan.labama.view_boom.widget_boom.TitleView_boom;

import java.util.TreeMap;


public class BdBkActActivity_Cote_boom extends BaseInfoActivity_boom {

    //private EditText firstNameEt,middleNameEt,lastNameEt;
    private AddBkActView_Cote_boom addBankAccountView;
    private Button nextBtn;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_bind_bk_act_cote_boom);
        init();
    }

    private void init(){
        TitleView_boom titleView = findViewById(R.id.activity_bind_bank_account_cote_view_title);
        setBackBtn_boom(titleView.getBackIb());

        nextBtn = findViewById(R.id.activity_bind_bank_account_cote_btn_submit);
        addBankAccountView = findViewById(R.id.activity_bind_bank_account_cote_view_add_bank_account);

        addBankAccountView.setProduct(product);
        addBankAccountView.setPageTag(pageTag);

        nextBtn.setOnClickListener(v -> {

            UserInfoHelper_boom.gInstance().addEventPoint((pageTag+"_SAVE_CLICK"));

            HttpManager_boom.getInstance().saveUserPointForBatch();

            if (ActList_boom.getInstance().gBankAccountList().size()==0){//无收款账户：弹窗提示，按键灰态
                showToast_boom("Veuillez ajouter au moins un compte de réception de prêt valide.");
            }else {//有收款账户且信息已输入：进入下一步流程
                new SubmitActInfoDialog_Fr_boom(this, v1 -> {

                    UserInfoHelper_boom.gInstance().addEventPoint((pageTag+"_SAVE_CONFIRM_CLICK"));

                    HttpManager_boom.getInstance().uploadInfo(UrlInfo_boom.gInstance().gKsw7(), parseData());
                }).show();
            }
        });
    }

    private TreeMap<String,String> parseData() {
        return new TreeMap<String,String>(){{
            put("bvn", UserInfoHelper_boom.gInstance().gMobile());
        }};
    }

    @Override
    protected void onResume() {
        super.onResume();
        HttpManager_boom.getInstance().fetchBoundBankAccount(product.gtProduct(),product.gtToken());
    }

    //添加钱包账户返回
    public void onBindBankAccountResponse(){
        AddBkActView_Cote_boom.addAccountFlag = true;
        HttpManager_boom.getInstance().fetchBoundBankAccount(product.gtProduct(),product.gtToken());
    }

    //删除账户返回
    public void onDeleteBankAccountResponse(){
        showToast_boom("Supprimé avec succès");
        HttpManager_boom.getInstance().fetchBoundBankAccount(product.gtProduct(),product.gtToken());
    }

    @Override
    public void onFetchBankAccountListResponse() {
        addBankAccountView.updateAccountList();
    }

}